package com.leetcode.No1805;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * @program: Solution
 * @description: 字符串中不同整数的数目
 * @author: Wang Zhihua
 * @date: 2022-12-09
 */
public class Solution {
    public int numDifferentIntegers(String word) {
        int len = word.length();
        Set<String> set = new HashSet<>();
        StringBuilder tmpNum = new StringBuilder();
        boolean isNum = false;
        for (int i = 0; i < len; ++i) {
            char ch = word.charAt(i);
            if (ch == '0') {
                if (tmpNum.length() > 0) {
                    tmpNum.append(ch);
                }
                isNum = true;
            } else if ('0' < ch && ch <= '9') {
                tmpNum.append(ch);
                isNum = true;
            } else if (isNum) {
                if (tmpNum.length() == 0) {
                    set.add("0");
                } else {
                    set.add(tmpNum.toString());
                }
                tmpNum = new StringBuilder(0);
                isNum = false;
            }
        }
        if (isNum) {
            if (tmpNum.length() == 0) {
                set.add("0");
            } else {
                set.add(tmpNum.toString());
            }
        }
        return set.size();
    }

    @Test
    public void test() {
//        System.out.println(numDifferentIntegers("a123bc34d8ef34"));
//
//        System.out.println(numDifferentIntegers("leet1234code234"));
//
//        System.out.println(numDifferentIntegers("a1b01c001"));

        System.out.println(numDifferentIntegers("0a0"));
    }
}
